class TheMonth {
  getMounthStartEnd (type, months) {
    var d = new Date()
    var year = d.getFullYear()
    var month = d.getMonth() + 1
    if (Math.abs(months) > 12) {
      months = months % 12
    }
    if (months !== 0) {
      if (month + months > 12) {
        year++
        month = (month + months) % 12
      } else if (month + months < 1) {
        year--
        month = 12 + month + months
      } else {
        month = month + months
      }
    }
    month = month < 10 ? '0' + month : month
    var date = d.getDate()
    var firstday = year + '-' + month + '-' + '01'
    var lastday = ''
    if (month === '01' || month === '03' || month === '05' || month === '07' || month === '08' || month === '10' || month === '12') {
      lastday = year + '-' + month + '-' + 31
    } else if (month === '02') {
      if ((year % 4 === 0 && year % 100 !== 0) || (year % 100 === 0 && year % 400 === 0)) {
        lastday = year + '-' + month + '-' + 29
      } else {
        lastday = year + '-' + month + '-' + 28
      }
    } else {
      lastday = year + '-' + month + '-' + 30
    }
    var day = ''
    if (type === 's') {
      day = firstday
    } else {
      day = lastday
    }
    return day
  }

  getMonth() {
    return [this.getMounthStartEnd('s', 0), this.getMounthStartEnd('e', 0)]
  }
}
// return [getMonth('s',0),getMonth('e',0)]

export default new TheMonth()
